#!/usr/bin/env bash
set -e

: "${WS_ROOT:=/mnt/ohos}"

if [ ! -d "$WS_ROOT" ]; then
    echo "ERROR: Required workspace directory WS_ROOT='$WS_ROOT' is not mounted."
    echo "Please run the container with:  docker run -v <host_dir>:$WS_ROOT <image>"
    exit 1
fi

if [ -z "$(ls -A "$WS_ROOT")" ]; then
    echo "!!! WARNING: WS_ROOT='$WS_ROOT' is mounted but empty."
fi

if [ -z "$(ls -A "$WS_ROOT/ros")" ]; then
    echo "!!! WARNING: WS_ROOT='$WS_ROOT/ros' (ros2 source repo) is empty."
fi

if [ -z "$(ls -A "$WS_ROOT/ohos-robot-toolchain")" ]; then
    echo "!!! WARNING: WS_ROOT='$WS_ROOT/ohos-robot-toolchain' (ohos-robot-toolchain) is empty."
fi

if [ -z "$(ls -A "$WS_ROOT/version")" ]; then
    echo "!!! WARNING: WS_ROOT='$WS_ROOT/version' (utilities repo) is empty."
fi


exec "$@"